import itchat

itchat.auto_login(hotReload=True)
friends = itchat.get_friends()[0:]
index = 1
for i in friends:
    index += 1
    if index >5:
        exit()
    img = itchat.get_head_img(userName=i['UserName'])
    path = "D:\\work\\python\\wechat\\headImg\\"+ i['NickName'] + '.jpg'
    print("正在下载:%s的头像" % i['NickName'])
    try:
        with open(path, 'wb') as f:
            f.write(img)
    except Exception as e:
        print(repr(e))

itchat.run()